const app = getApp();
var request = app.request;
var util = require('../../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    url: app.globalData.setting.url,
    statusBar: app.globalData.statusBar,
    userInfo: app.globalData.userInfo,
    orderNum: 0,
    teamNum: 0,
    showCode: false
  },
  onLoad() {
    this.getQrCode();
    this.getOrderNum();
    this.getTeamNum();
  },
  // 获取订单数量
  getOrderNum() {
    var that = this;
    request.get('/api/Distribut/order_list?status=&pageSize=10000', {
      isShowLoading:false,
			success: function (res) {
				that.setData({
					orderNum: res.data.result.length
        })
			}
		});
  },
  // 获取团队数量
  getTeamNum() {
    var that = this;
    request.get('/api/Distribut/lower_list/level/1', {
      isShowLoading:false,
			success: function (res) {
				that.setData({
					teamNum: res.data.result.fcount + res.data.result.scount
        })
			}
		});
  },
  getUserInfo() {
    var that = this;
    app.getUserInfo(function (userInfo) {
      userInfo["distribut_can_withdrawals_money"] = util.formatNumber(userInfo.distribut_money - userInfo.distribut_withdrawals_money);
      that.setData({
          userInfo: userInfo
      });
  }, true, false); 
  },
  getQrCode() {
    var that = this;
    request.post('/api/Distribut/qr_code', {
      isShowLoading:true,
			success: function () {
        that.getUserInfo();
      }
		});
  },
  showCode() {
    if(!this.data.userInfo.xcx_qrcode) {
      app.showTextWarining('请先加入会员')
      return;
    }
    this.setData({
      showCode: !this.data.showCode
    })
  },
  // 返回上一页
  back() {
    wx.navigateBack();
  }
})